upstream unicorn_<%= fetch(:application) %> {
  server unix:/tmp/unicorn.<%= fetch(:application) %>.sock fail_timeout=0;
}

server {
  server_name <%= fetch(:url) %> www.<%= fetch(:url) %>;
  listen <%= server.hostname %>;

  location / {
    root /home/<%= fetch(:user) %>/apps/<%= fetch(:application) %>/current/public;
    try_files $uri/index.html $uri @unicorn_<%= fetch(:application) %>;
  }

  location ^~ /assets/ {
    root /home/<%= fetch(:user) %>/apps/<%= fetch(:application) %>/current/public;
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    access_log off;
  }

  location /status {
    stub_status on;
    access_log off;
    allow <%= server.hostname %>;
    deny all;
  }

  location @unicorn_<%= fetch(:application) %> {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn_<%= fetch(:application) %>;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;

}